package com.qiku.controller;

import com.qiku.authority.pojo.PromotionAd;
import com.qiku.server.PromotionAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 广告控制层
 */
@RestController   //  ResponseBody  当前类中所有方法的返回值 会被转换位json
@CrossOrigin // 解决跨域问题
@RequestMapping("/ad")
public class PromotionAdController {

    /**
     * 根据类型注入  如果IOC容器中有多个，那可以借助 @Qualifier 指定要注入的bean的id
     */
    @Autowired
//    @Qualifier("promotionAdServerImpl")
    private PromotionAdService promotionAdService;


    /**
     * 根据广告位的id 获取广告信息
     * @return
     * 读取路径中的参数 并将参数的值 赋值给 sid
     * @PathVariable(name = "sid")
     */
    @GetMapping("/getAdsBySpaceId/{spaceid}")
    public List<PromotionAd> getAdsBySpaceId(@PathVariable(name = "spaceid") Integer sid){
        List<PromotionAd> adList = promotionAdService.getAdsBySpaceId(sid);
        return adList;
    }




    @GetMapping("/findAll")
    public List<PromotionAd> findAll(){
        return promotionAdService.list();
    }


    @GetMapping("/select/{id}")
    public PromotionAd selectById(@PathVariable Integer id){
        return promotionAdService.getById(id);
    }



    @GetMapping("/delete/id")
    public void deleteByid(@PathVariable Integer id){
        promotionAdService.removeById(id);
    }

    @GetMapping("/deletes/{id}")
    public void deletes(@PathVariable Integer[] ids){
        promotionAdService.removeByIds(List.of(ids));
    }

    @PostMapping("/saveOrupdate")
    public void saveOrupdate(@RequestBody PromotionAd promotionAd){
        promotionAdService.saveOrUpdate(promotionAd);

    }

}
